<style type="text/css">
    .demo-upload-list {
        display: inline-block;
        width: 60px;
        height: 60px;
        text-align: center;
        line-height: 60px;
        border: 1px solid transparent;
        border-radius: 4px;
        overflow: hidden;
        background: #fff;
        position: relative;
        box-shadow: 0 1px 1px rgba(0, 0, 0, .2);
        margin-right: 4px;
    }

    .demo-upload-list img {
        width: 100%;
        height: 100%;
    }

    .demo-upload-list-cover {
        display: none;
        position: absolute;
        top: 0;
        bottom: 0;
        left: 0;
        right: 0;
        background: rgba(0, 0, 0, .6);
    }

    .demo-upload-list:hover .demo-upload-list-cover {
        display: block;
    }

    .demo-upload-list-cover i {
        color: #fff;
        font-size: 20px;
        cursor: pointer;
        margin: 0 2px;
    }

    .selected-search {
        border: 1px solid #dddee1;
        height: 200px;
        width: 260px;
        position: relative;
        border-radius: 4px;
    }

    .selected-search .search-action {
        position: absolute;
        top: 10px;
        left: 10px;
        right: 10px;
    }

    .selected-search .selected-arr {
        position: absolute;
        top: 50px;
        left: 20px;
        right: 20px;
        bottom: 10px;
        overflow: scroll;
    }

    .select-click {
        border: 1px solid #dddee1;
        border-radius: 4px;
        padding: 0 10px;
        margin-bottom: 10px;
    }

    .selected-search .selected-arr .selected-item {
        /*border-bottom: 1px solid #dfdfdf;*/
    }
</style>
<template>
    <i-form ref="formValidate" :model="formValidate" :rules="ruleValidate" :label-width="100">
        <Form-item label="车牌区域" prop="Visitcontactid">
            <p @click="getCarCityData()" class="select-click">{{personalName}}</p>
            <div v-if="selectPeopelIsShow" class="selected-search">
                <div class="selected-arr">
                    <template v-for="(item,index) in carCityArr">
                        <p @click="choosePeople(item.id,item.code)" class="selected-item">
                            {{item.code}}</p>
                    </template>
                </div>
            </div>
        </Form-item>
        <Form-item label="车牌号" prop="carcode">
            <i-input v-model="formValidate.carcode" placeholder="请输入车牌号"></i-input>
        </Form-item>
        <Form-item label="车辆类型" prop="cartype">
            <i-select v-model="formValidate.cartype" placeholder="请选择车辆类型">
                <template v-for="(item,index) in carTypeArr">
                    <i-option :value="item">{{item}}</i-option>
                </template>
            </i-select>
        </Form-item>
        <Form-item label="联系人" prop="people">
            <i-input v-model="formValidate.people" placeholder="请输入联系人"></i-input>
        </Form-item>
        <Form-item label="联系人电话" prop="phone">
            <i-input v-model="formValidate.phone" placeholder="请输入联系人电话"></i-input>
        </Form-item>
        <Form-item label="编号" prop="cardno">
            <i-input v-model="formValidate.cardno" placeholder="请输入编号"></i-input>
        </Form-item>
        <!--<Form-item label="被访问人员" prop="Visitcontactid">-->
        <!--<p @click="getPeopelData()" class="select-click">{{personalName}}</p>-->
        <!--<div v-if="selectPeopelIsShow" class="selected-search">-->
        <!--<div class="search-action">-->
        <!--<i-input v-model="formValidate.Visitcontactid" placeholder="请输入访问部门"></i-input>-->
        <!--</div>-->
        <!--<div class="selected-arr">-->
        <!--<template v-for="(item,index) in principalArr">-->
        <!--<p @click="choosePeople(item.id,item.personalname)" class="selected-item">{{item.personalname}}</p>-->
        <!--</template>-->
        <!--</div>-->
        <!--</div>-->
        <!--</Form-item>-->
        <!--<Form-item label="电话" prop="Visitorphone">-->
        <!--<i-input v-model="formValidate.Visitorphone" placeholder="请输入电话"></i-input>-->
        <!--</Form-item>-->
        <!--<Form-item label="开始时间" >-->
            <!--<Row>-->
                <!--<i-col span="11">-->
                    <!--<Date-picker type="datetime" placeholder="选择开始日期" @on-change="changeStartDate"></Date-picker>-->
                <!--</i-col>-->
            <!--</Row>-->
        <!--</Form-item>-->
        <!--<Form-item label="结束时间" >-->
            <!--<Row>-->
                <!--<i-col span="11">-->
                    <!--<Date-picker type="datetime" placeholder="选择结束日期" @on-change="changeEndDate"></Date-picker>-->
                <!--</i-col>-->
            <!--</Row>-->
        <!--</Form-item>-->
        <!--上传图片-->
        <!--<Form-item label="封面" prop="image">-->
        <!--<div class="demo-upload-list" v-for="item in imageList">-->
        <!--<template v-if="item.status === 'finished'">-->
        <!--<img :src="apiUtilBase + item.response.Msg">-->
        <!--<div class="demo-upload-list-cover">-->
        <!--<Icon type="ios-eye-outline" @click="handleView(apiUtilBase + item.response.Msg)"></Icon>-->
        <!--<Icon type="ios-trash-outline" @click="handleRemove(item)"></Icon>-->
        <!--</div>-->
        <!--</template>-->
        <!--<template v-else>-->
        <!--<Progress v-if="item.showProgress" :percent="item.percentage" hide-info></Progress>-->
        <!--</template>-->
        <!--</div>-->
        <!--<Upload ref="upload"-->
        <!--:show-upload-list="false"-->
        <!--:default-file-list="defaultList"-->
        <!--:on-success="handleSuccess"-->
        <!--:format="['jpg','jpeg','png']"-->
        <!--:max-size="2048"-->
        <!--:name="'uploadFile'"-->
        <!--:on-format-error="handleFormatError"-->
        <!--:on-exceeded-size="handleMaxSize"-->
        <!--:before-upload="handleBeforeUpload"-->
        <!--multiplelayout-content-->
        <!--type="drag"-->
        <!--:action="upLoadFile"-->
        <!--style="display: inline-block;width:58px;">-->
        <!--<div style="width: 58px;height:58px;line-height: 58px;">-->
        <!--<Icon type="camera" size="20"></Icon>-->
        <!--</div>-->
        <!--</Upload>-->
        <!--<Modal title="查看图片" v-model="visible">-->
        <!--<img :src="seeImg" v-if="visible" style="width: 100%">-->
        <!--</Modal>-->
        <!--</Form-item>-->
        <Form-item>
            <i-button @click="handleSubmit('formValidate')" type="primary">提交</i-button>
            <i-button type="ghost" @click="jumpPage()" style="margin-left: 8px">返回</i-button>
        </Form-item>

    </i-form>

</template>
<script>
    import apiUtil from '../../assets/utils/api_util';
    import carCity from '../../assets/utils/car_city';

    /**
     * visitorid，来访人员的ID
     carcode，车牌号
     cartype，车辆类型
     people，车辆联系人
     phone，车辆联系人电话
     cardno，分配的车辆准入卡编号（如果有才填写）
     expiredatestart，准入有效期的起始时间
     expiredateend，准入有效期的结束时间
     */
    export default {
        data() {
            return {
                carTypeArr: [
                    '大型汽车', '小型汽车', '专用汽车', '特种车', '电瓶车', '三轮摩托车', '二轮摩托车', '四轮农用运输车', '三轮农用运输车',
                ],
                formValidate: {
                    //添加字段
                    carcode: '',
                    cartype: '',
                    people: '',
                    phone: '',
                    cardno: '',
                },
                ruleValidate: {
                    // carcode: [
                    //     {required: true, message: '车牌号', trigger: 'blur'}
                    // ],
                    // cartype: [
                    //     {required: true, message: '请选择车辆分类 ', trigger: 'change'}
                    // ],
                    // people: [
                    //     {required: true, message: '车辆联系人不能为空', trigger: 'blur'}
                    // ],
                    // phone: [
                    //     {required: true, message: '联系人电话不能为空', trigger: 'blur'}
                    // ],
                    // expiredatestart: [
                    //     {required: true, type: 'date', message: '请选择时间', trigger: 'change'}
                    // ],
                    // expiredateend: [
                    //     {required: true, type: 'date', message: '请选择时间', trigger: 'change'}
                    // ],
                },
                papertypeArr: [],
                //被访问人员列表
                principalId: '',
                principalArr: [],
                personalName: '请选择',
                selectPeopelIsShow: false,
                //图片
                defaultList: [],
                imageList: '',
                imagePost: [],
                visible: false,
                seeImg: '',
                upLoadFile: apiUtil.urls.UploadFile,
                apiUtilBase: apiUtil.urls.baseUrl,
                //车辆区域
                carCityArr: [],
            }
        },
        mounted: function () {
            this.uploadList();
        },

        methods: {
            //跳转
            jumpPage: function (id, url) {
                this.$router.back(-1)

            },
            changeStartDate: function (date) {
                console.log(date)
                this.formValidate.expiredatestart = date;
            },
            changeEndDate: function (date) {
                console.log(date)
                this.formValidate.expiredateend = date;

            },
            handleSubmit(name) {

                let that = this;
                let model = this.$refs[name].model;
                this.$refs[name].validate((valid) => {
                    that.addData(model);
                })
            },
            //获取车牌
            getCarCityData() {
                let that = this;

                this.carCityArr = carCity;
                if (this.selectPeopelIsShow) {
                    this.selectPeopelIsShow = false;
                } else {
                    this.selectPeopelIsShow = true;
                }
                console.log('车辆地区:', carCity)
            },
            choosePeople: function (id, name) {
                this.principalId = id;
                this.personalName = name;
                this.selectPeopelIsShow = false;
            },

            //添加
            addData: function (model) {
                let that = this;

                model.visitorid = this.$route.query.id;
                model.operatorId = 'c1d1ae1f-2038-4425-b2cc-0e5cc49fcd44';
                model.carcode = this.personalName + '-' + model.carcode;
                let params = that.$qs.stringify(model);
                this.$Loading.start();

                apiUtil.post(that, apiUtil.urls.AddVisitorCar, params, function (res) {
                    that.$Loading.finish();

                    that.$Notice.open({
                        title: '通知',
                        desc: '添加成功 ',
                        duration: 0
                    });

                });
            },

            uploadList() {
                let that = this;
                this.imageList = that.$refs.upload ? that.$refs.upload.fileList : [];
                console.log('this.imageList:', this.imageList);
                // return ;
            },

            /*
            * 图片
            * */

            //预览上传图片
            handleView(url) {
                this.seeImg = url;
                this.visible = true;
                console.log('预览照片')
            },
            //删除图片
            handleRemove(file) {
                // 从 upload 实例删除数据
                let that = this;

                that.imagePost = [];

                const fileList = this.$refs.upload.fileList;
                this.$refs.upload.fileList.splice(fileList.indexOf(file), 1);
                this.$refs.upload.fileList.forEach(function (item, i) {
                    that.imagePost.push(that.apiUtilBase + item.response.Msg);
                });
            },
            //上传成功
            handleSuccess(res, file) {
                let that = this;
                file.url = file.response.data;
                that.imagePost = [];

                console.log('this.$refs.upload:', this.$refs.upload.fileList);
                this.$refs.upload.fileList.forEach(function (item, i) {
                    let imgItem = {
                        "img": item.response.Msg
                    }
                    that.imagePost.push(imgItem);
                });
                console.log('this.imagePost:', this.imagePost)
            },
            //上传成功
            handleFormatError(file) {
                this.$Notice.warning({
                    title: '文件格式不正确',
                    desc: '文件 ' + file.name + ' 格式不正确，请上传 jpg 或 png 格式的图片。'
                });
            },
            handleMaxSize(file) {
                this.$Notice.warning({
                    title: '超出文件大小限制',
                    desc: '文件 ' + file.name + ' 太大，不能超过 2M。'
                });
            },
            handleBeforeUpload() {
                const check = this.imageList.length < 6;
                if (!check) {
                    this.$Notice.warning({
                        title: '最多只能上传6张图片。'
                    });
                }
                return check;
            }
        }
    }
</script>
